let Mock = require('mockjs')
let data = [{
    "id":0,
    "biaoshi":"LOC_TYPE",
    "title":"日志类型",
    "key":"键值对",
    "item":"1:业务,2:登录,3:系统",
    "time":"2018-10-05 20:28:47",
    "newTime":"2019-02-26 00:31:43"
},{
    "id":1,
    "biaoshi":"SEARCH_STSTUS",
    "title":"搜索栏状态",
    "key":"键值对",
    "item":"1:业务,2:冻结",
    "time":"2018-10-05 20:25:45",
    "newTime":"2019-02-26 00:34:34"
},{
    "id":2,
    "biaoshi":"MENU_TYPE",
    "title":"日志类型",
    "key":"键值对",
    "item":"1:一级菜单,2:子集菜单,3:不是菜单",
    "time":"2018-10-05 20:24:57",
    "newTime":"2018-10-13 13:56:05"
},{
    "id":3,
    "biaoshi":"USER_SEX",
    "title":"用户性别",
    "key":"键值对",
    "item":"1:男,2:女",
    "time":"2018-10-05 20:12:32",
    "newTime":"2018-10-05 20:12:32"
},{
    "id":4,
    "biaoshi":"DICT_TYPE",
    "title":"字典类型",
    "key":"键值对",
    "item":"2:键值对",
    "time":"2018-10-05 20:08:55",
    "newTime":"2019-01-17 23:39:23"
},{
    "id":5,
    "biaoshi":"DATA_STATUS",
    "title":"数据状态",
    "key":"键值对",
    "item":"1:正常,2:冻结,3:删除",
    "time":"2018-10-05 16:03:11",
    "newTime":"2018-10-05 16:11:41"
}]
Mock.mock("/api/diction","get",function(config){
    return data
})
Mock.mock(/\/api\/diction\/edit\/\d/, "put", function(config) {
    console.log(config);

    let item = JSON.parse(config.body)
    let arr = config.url.split("/")
    let id = arr[arr.length - 1]
    data.splice(id, 1, item)
    return item
})
// 添加
Mock.mock("/api/diction", "post", function(config) {
    let obj = JSON.parse(config.body)
    console.log(obj)
    data.push(obj)
    return data
})
// 删除
Mock.mock(/\/api\/diction\/delete\/\d/, "delete", function(config) {
    console.log(config)
    let arr = config.url.split("/")
    let id = arr[arr.length - 1]
    data.splice(id, 1)
    return "删除成功"
})